package com.ph.irp.base.salespricepolicy.service.impl;

import java.util.List;

import com.ph.irp.base.salespricepolicy.dao.PBaseSalesPricePolicyDAO;
import com.ph.irp.base.salespricepolicy.service.SalesPricePolicyService;
import com.ph.irp.model.PBaseSalespricepolicy;

public class SalesPricePolicyServiceImpl implements SalesPricePolicyService {

	PBaseSalesPricePolicyDAO salespricepolicyDaoProxy;

	public PBaseSalesPricePolicyDAO getSalespricepolicyDaoProxy() {
		return salespricepolicyDaoProxy;
	}

	public void setSalespricepolicyDaoProxy(
			PBaseSalesPricePolicyDAO salespricepolicyDaoProxy) {
		this.salespricepolicyDaoProxy = salespricepolicyDaoProxy;
	}

	/*
	 * 查询销售价格政策
	 */
	@Override
	public List<PBaseSalespricepolicy> getSalesPricePolicyList(
			PBaseSalespricepolicy salespricepolicyModel) throws Throwable {
		// TODO Auto-generated method stub
		if (salespricepolicyModel == null) {
			return salespricepolicyDaoProxy.getAllSalesPricePolicyList();
		} else if (!salespricepolicyModel.getSalesPricePolicyCode().equals("")
				&& !salespricepolicyModel.getSalesPricePolicyName().equals("")) {
			return salespricepolicyDaoProxy.getSalespricePolicyByCodeAndName(
					salespricepolicyModel.getSalesPricePolicyCode(),
					salespricepolicyModel.getSalesPricePolicyName());
		} else {
			if (!salespricepolicyModel.getSalesPricePolicyCode().equals("")) {
				return salespricepolicyDaoProxy
						.getSalespricePolicyByCode(salespricepolicyModel
								.getSalesPricePolicyCode());
			} else if (!salespricepolicyModel.getSalesPricePolicyName().equals(
					"")) {
				return salespricepolicyDaoProxy
						.getSalespricePolicyByName(salespricepolicyModel
								.getSalesPricePolicyName());
			} else {
				return salespricepolicyDaoProxy.getAllSalesPricePolicyList();
			}
		}
	}

	/*
	 * 按照销售价格政策ID查询
	 */
	@Override
	public PBaseSalespricepolicy getSalesPricePolicyById(
			Integer salesPricePolicyId) throws Throwable {
		return salespricepolicyDaoProxy
				.getSalespricepolicyById(salesPricePolicyId);
	}

	/*
	 * 添加销售价格政策记录
	 */
	@Override
	public void addSalesPricePolicy(PBaseSalespricepolicy salespricepolicyModel)
			throws Throwable {
		salespricepolicyDaoProxy.addSalespricePolicy(salespricepolicyModel);
	}

	/*
	 * 更新销售价格政策记录
	 */
	@Override
	public void updateSalesPricePolicy(
			PBaseSalespricepolicy salespricepolicyModel) throws Throwable {
		salespricepolicyDaoProxy.updateSalespricePolicy(salespricepolicyModel);
	}

	/*
	 * 删除选中记录
	 */
	@Override
	public void deleteSalesPricePolicy(Integer salesPricePolicyId)
			throws Throwable {
		// TODO Auto-generated method stub
		salespricepolicyDaoProxy.deleteSalespricePolicy(salesPricePolicyId);
		PBaseSalespricepolicy salespricepolicy = new PBaseSalespricepolicy();
		salespricepolicy.setSalesPricePolicyId(salesPricePolicyId);
	}

	@Override
	public List<PBaseSalespricepolicy> getByCode(String salespricepolicyCode)
			throws Throwable {
		return salespricepolicyDaoProxy
				.getSalespricePolicyByCode(salespricepolicyCode);
	}

	@Override
	public List<PBaseSalespricepolicy> getByName(String salespricepolicyName)
			throws Throwable {
		return salespricepolicyDaoProxy
				.getSalespricePolicyByName(salespricepolicyName);
	}

	@Override
	public List<PBaseSalespricepolicy> getByNameAndCode(
			String salespricepolicyName, String salespricepolicyCode)
			throws Throwable {
		return salespricepolicyDaoProxy.getSalespricePolicyByCodeAndName(
				salespricepolicyCode, salespricepolicyName);
	}
}
